package DARCOServer;

import java.io.File;

import DARCOServer.Messaging.MessagingManager;
import DARCOServer.security.SecurityManager;
import DARCOServer.db.*;
import DARCOShared.utils.MachineSpecificConstants;
import DARCOShared.utils.NetUtils;


public class MainClass {
	public static void main(String [] args){
		//security initialization
		SecurityManager.Initialize();

		//create DB
		File f = new File("db.sql");
		boolean startFromScratch = !f.exists(); 
		System.out.println("Loading Database...");
		DatabaseManager.Initialize("db.sql", startFromScratch); //arg2 = true rifa' db da zero, se =false invece carica solamente
		System.out.println("DataBase loaded!");

		//test  card data
		if(startFromScratch){
			System.out.println("loading card data to db");
			CardDataToServerDB c = new CardDataToServerDB();
			c.putCardsIntoServerDB(DatabaseManager.getDatabaseInstance());

			System.out.println("loading account data to db");	
			AccountDataToServerDB a = new AccountDataToServerDB();
			a.putAccountsIntoServerDB(DatabaseManager.getDatabaseInstance());
			System.out.println("done!");
		}

		System.out.println("Starting server...");
		NetUtils.setServerIP();
		MessagingManager mm = new MessagingManager();
		mm.OpenConnection();
		System.out.println("Server up and listening!");

	}
}
